# leetcode 150 逆波兰表达式求值

# 遇见数字入栈，遇见操作符，则从栈中取出栈顶两个元素进行运算，然后将运算结果入栈


class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        stack = [] 
        symbols = {'+', '-', '*', '/'}
        for i in tokens:
            if i not in symbols:
                stack.append(i)
            else:
                n1 = stack.pop()
                n2 = stack.pop()
                tmp = int(eval(n2 + i + n1))
                stack.append(str(tmp))
        return int(stack[-1])
